package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService iSearchService;

    /**
     * 自动补全
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String prefix) {
        return iSearchService.getSuggestion(prefix);
    }

    /**
     * 过滤项聚合功能
     * @param params
     * @return
     */
    @PostMapping("/filters")
    public Map<String,List<String>> filters(@RequestBody RequestParams params){
        return iSearchService.getFilters(params);
    }

    /**
     * 搜索功能
     * @param params
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> getlist(@RequestBody RequestParams params){
        return iSearchService.getList(params);
    }
}
